<?php
/**
* @version $Id: user.html.php 10002 2008-02-08 10:56:57Z willebil $
* @package Joomla
* @subpackage Users
* @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );

/**
* @package Joomla
* @subpackage Users
*/
class HTML_user {
	function frontpage() {
		?>
		<div class="componentheading">
			<?php echo _WELCOME; ?>
		</div>

		<table cellpadding="0" cellspacing="0" border="0" width="100%">
		<tr>
			<td>
				<?php echo _WELCOME_DESC; ?>
			</td>
		</tr>
		</table>
		<?php
	}

	function userEdit( $row, $option, $submitvalue, &$params, &$listCity, &$lsDistrict ) {
		global $mosConfig_absolute_path, $mosConfig_frontend_userparams, $mosConfig_live_site;
		global $database;

		require_once( $mosConfig_absolute_path .'/includes/HTML_toolbar.php' );

		// used for spoof hardening
		$validate = josSpoofValue();
		
		mosCommonHTML::loadOverlib();		
		?>
		<script language="JavaScript" src="<?php echo $mosConfig_live_site; ?>/includes/js/joomla.javascript.js" type="text/javascript"></script>
		<link rel="stylesheet" href="<?php echo $mosConfig_live_site; ?>/plugin/jwysiwyg/jwysiwyg/jquery.wysiwyg.css" type="text/css" />
		<script type="text/javascript" src="<?php echo $mosConfig_live_site; ?>/plugin/jwysiwyg/jwysiwyg/jquery.wysiwyg.js"></script>
		<script language="javascript" type="text/javascript">
		function delete_extra_options (selobj, size)
		{
			while (selobj . options . length > size)
				selobj . options [selobj . options . length - 1] = null;
		}
		
		function update_item_list ()
		{
			var cat_selobj = document . mosUserForm . city_id;
			var item_selobj = document . mosUserForm . district_id;
			var choice = cat_selobj . options [cat_selobj . selectedIndex] . value;
			<?php
			for ($i=0; $i<count($listCity); $i++){
				?>
				if (choice == <?php echo $listCity[$i]->id;?>)
				{
					<?php
					$sql = "select count(*) from #__district where published=1 and city_id=".$listCity[$i]->id;
					$database->setQuery($sql);
					$total = $database->loadResult();
					$sql = "select * from #__district where published=1 and city_id=".$listCity[$i]->id." order by title asc, id desc";
					$database->setQuery($sql);
					$listDistrict = $database->loadObjectList();
					for ($j=0; $j<count($listDistrict); $j++){
					?>
					item_selobj . options [<?php echo $j;?>] = new Option ("<?php echo $listDistrict[$j]->title;?>","<?php echo $listDistrict[$j]->id;?>");
					<?php
					}
					?>
					delete_extra_options (item_selobj, <?php echo $total;?>);
				}
				<?php
			}
			?>
		}
		function submitbutton( pressbutton ) {
			var form = document.mosUserForm;
			var r = new RegExp("[\<|\>|\"|\'|\%|\;|\(|\)|\&|\+|\-]", "i");

			if (pressbutton == 'cancel') {
				form.task.value = 'cancel';
				form.submit();
				return;
			}

			// do field validation
			if (form.name.value == "") {
				alert( "<?php echo addslashes( _REGWARN_NAME );?>" );
			} else if (form.username.value == "") {
				alert( "<?php echo addslashes( _REGWARN_UNAME );?>" );
			} else if (r.exec(form.username.value) || form.username.value.length < 3) {
				alert( "<?php printf( addslashes( _VALID_AZ09 ), addslashes( _PROMPT_UNAME ), 4 );?>" );
			} else if (form.email.value == "") {
				alert( "<?php echo addslashes( _REGWARN_MAIL );?>" );
			} else if ((form.password.value != "") && (form.password.value != form.verifyPass.value)){
				alert( "<?php echo addslashes( _REGWARN_VPASS2 );?>" );
			} else if (r.exec(form.password.value)) {
				alert( "<?php printf( addslashes( _VALID_AZ09 ), addslashes( _REGISTER_PASS ), 4 );?>" );
			} else {
				form.submit();
			}
		}
		$(document).ready(function() {
			<?php 
    		if ($row->user_class==1){
	    		?>
	    		$('.user_normal').hide();
	    		<?php 
			}else{
	    		?>
	    		$('.user_normal').show();
	    		<?php 
			}
    		?>
			//Load editor
	    	$(function()
    		{
    			$('#wysiwyg').wysiwyg();
    		});
	    });
		</script>
		<form action="index.php" method="post" name="mosUserForm">
		<div class="user_heading">
			<div id="title_form"><?php echo _EDIT_TITLE; ?></div>
			<div id="toolbar">
			<?php
			mosToolBar::startTable();
			mosToolBar::spacer();
			mosToolBar::save();
			mosToolBar::cancel();
			mosToolBar::endtable();
			?>
			</div>
		</div>
		<table class="adminlist" cellpadding="5" cellspacing="0" border="0" width="100%">
		<tr>
			<td width="150">
				<?php echo _YOUR_NAME; ?>
			</td>
			<td>
				<input class="inputbox" type="text" name="name" value="<?php echo $row->name;?>" size="40" />
			</td>
		</tr>
		<tr>
			<td>
				<?php echo _EMAIL; ?>
			</td>
			<td>
				<input class="inputbox" type="text" name="email" value="<?php echo $row->email;?>" size="40" />
			</td>
		</tr>
		<tr>
			<td>
				<?php echo _UNAME; ?>
			</td>
			<td>
				<input class="inputbox" type="text" name="username" value="<?php echo $row->username;?>" size="40" />
			</td>
		</tr>
		<tr>
			<td>
				<?php echo _PASS; ?>
			</td>
			<td>
				<input class="inputbox" type="password" name="password" value="" size="40" />
			</td>
		</tr>
		<tr>
			<td>
				<?php echo _VPASS; ?>
			</td>
			<td>
				<input class="inputbox" type="password" name="verifyPass" size="40" />
			</td>
		</tr>
		<tr>
			<td valign="top">
			<?php
			if ($row->user_class==1){
				echo 'Logo công ty';
				$name_dir = 'logo';
			}else{
				echo 'Avatar cá nhân';
				$name_dir = 'avatar';
			}
			?>					
			</td>
			<td>
			<img src="<?php echo $mosConfig_live_site;?>/uploads/users/<?php echo $name_dir."/".$row->img;?>" width="130" border="0" />
			<br />
			<input type="file" name="img" size="30" />
			</td>
		</tr>
		<tr>
			<td><?php echo _REGISTER_ADDRESS; ?> :</td>
			<td><input class="inputbox" type="text" name="address" value="<?php echo $row->address;?>" size="40" /></td>
		</tr>
		<tr>
			<td>
				<?php echo _REGISTER_CITY_ID; ?>
			</td>
			<td>
				<select onChange="update_item_list();" size="1" name="city_id" id="city_id" title="Chọn" class="inputbox" style="width:150px;">
					<option value="">--[Chọn]--</option>
					<?php
					for ($i=0; $i<count($listCity); $i++){
						if ($listCity[$i]->id == $row->city_id) $selected = ' selected="selected"';
						else $selected = '';
						echo "<option value='".$listCity[$i]->id."'".$selected.">".$listCity[$i]->title."</option>";
					}
					?> 
				</select>
			</td>
		</tr>
		<tr>
			<td>
				<?php echo _REGISTER_DISTRICT_ID; ?>
			</td>
			<td>
				<select onchange="" size="1" name="district_id" id="district_id" title="Chọn" class="inputbox" style="width:150px;">
					<?php
					for ($i=0; $i<count($lsDistrict); $i++){
						if ($lsDistrict[$i]->id == $row->district_id) $selected = ' selected="selected"';
						else $selected = '';
						echo "<option value='".$lsDistrict[$i]->id."'".$selected.">".$lsDistrict[$i]->title."</option>";
					}
					?> 
				</select>
			</td>
		</tr>
		<tr>
			<td><?php echo _REGISTER_MOBILE; ?> :</td>
			<td><input class="inputbox" type="text" name="mobile" value="<?php echo $row->mobile;?>" size="40" /></td>
		</tr>
		<tr class="user_normal">
			<td>
				<?php echo _REGISTER_SEX; ?>
			</td>
			<td>
				<select onchange="" size="1" name="sex" id="sex" title="Chọn" class="inputbox" style="width:80px;">
					<option value="1"<?php if ($row->sex==1) echo ' selected="selected"';?>>Nam</option>
					<option value="0"<?php if ($row->sex==0) echo ' selected="selected"';?>>Nữ</option>
				</select>
			</td>
		</tr>
		<tr class="user_normal">
			<td>
				<?php echo _REGISTER_BIRTHDAY; ?>
			</td>
			<td>
				<input class="inputbox" type="text" name="birthday" id="birthday" size="25" style="width:150px;" value="<?php echo $row->birthday;?>" />
				<input name="reset" type="reset" class="button" onclick="return showCalendar('birthday', 'y-mm-dd');" value="..." />
			</td>
		</tr>
		<tr>
			<td><?php echo _REGISTER_YAHOO; ?> :</td>
			<td><input class="inputbox" type="text" name="yahoo" value="<?php echo $row->yahoo;?>" size="40" /></td>
		</tr>
		<tr>
			<td><?php echo _REGISTER_SKYPE; ?> :</td>
			<td><input class="inputbox" type="text" name="skype" value="<?php echo $row->skype;?>" size="40" /></td>
		</tr>
		<tr>
			<td><?php echo _REGISTER_WEBSITE; ?> :</td>
			<td><input class="inputbox" type="text" name="website" value="<?php echo $row->id ? $row->website : 'http://';?>" size="40" /></td>
		</tr>
		<tr>
			<td valign="top"><?php echo _REGISTER_ABOUTS; ?> :</td>
			<td><textarea name="content" id="wysiwyg" cols="63" rows="12"><?php echo $row->content;?></textarea></td>
		</tr>
		</table>

		<input type="hidden" name="id" value="<?php echo $row->id;?>" />
		<input type="hidden" name="option" value="<?php echo $option;?>" />
		<input type="hidden" name="task" value="saveUserEdit" />
		<input type="hidden" name="<?php echo $validate; ?>" value="1" />
		</form>
		<?php
	}

	function confirmation() {
		?>
		<div class="componentheading">
			<?php echo _SUBMIT_SUCCESS; ?>
		</div>

		<table>
		<tr>
			<td>
				<?php echo _SUBMIT_SUCCESS_DESC; ?>
			</td>
		</tr>
		</table>
		<?php
	}
	
	//VIP
	/**
	 * Show List Products
	*/
	function showListProducts( $title_page, $total, &$rows, $task ){
		global $mosConfig_live_site, $mosConfig_absolute_path;
		
		require_once( $mosConfig_absolute_path .'/includes/HTML_toolbar.php' );
		$hiddenmain  = intval(mosGetParam($_REQUEST, 'hiddenmain', 0));
		
		$imageurl 	= $mosConfig_live_site."/uploads/content";
		if ($hiddenmain == 0 || !$hiddenmain){
		?>
		<script language="JavaScript" src="<?php echo $mosConfig_live_site;?>/includes/js/JSCookMenu_mini.js" type="text/javascript"></script>
		<script language="JavaScript" src="<?php echo $mosConfig_live_site;?>/includes/js/joomla.javascript.js" type="text/javascript"></script>
		<form name="adminForm" method="post" action=""<?php echo $styleForm;?>>
		<div class="user_heading">
			<div id="title_form"><?php echo $title_page;?></div>
			<div id="toolbar">
			<?php
			mosToolBar::startTable();
			mosToolBar::publishIcon();
			mosToolBar::unpublishIcon();
			mosToolBar::addNewIcon();
			mosToolBar::editIcon();
			mosToolBar::deleteIcon();
			mosToolBar::endtable();
			?>
			</div>
		</div>
		<table class="adminlist">
			<thead>
				<tr>
					<th width="5">
						<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo $total; ?>);" />
					</th>
					<th>Ảnh</th>
					<th>Tên sản phẩm</th>
					<th>Thể loại</th>
					<th>Ngày đăng</th>
					<th>Nhóm VIP</th>
					<th>Nhóm HOT</th>
					<th width="8%">Hiển thị</th>
					<th>Thống kê</th>
				</tr>
			</thead>
			<tbody>
			<?php if ($total>0){
				for ($i=0; $i<count($rows); $i++){
				$link = sefRelToAbs("index.php?option=com_content&task=view&catid=".$rows[$i]->catid."&id=".$rows[$i]->id).$rows[$i]->title_alias.".html";
				$linkEdit = sefRelToAbs("index.php?option=com_user&task=edit&id=".$rows[$i]->id."&hiddenmain=1").$rows[$i]->title_alias.".html";
				$linkCat = sefRelToAbs("index.php?option=com_user&task=showList&catid=".$rows[$i]->catid).$rows[$i]->html_namecat.".html";
				if (($i+1)%2 == 0) $str_class = "row1"; else $str_class = "row0";
				if ($rows[$i]->state == 1){
					$img = 'tick.png';
					$alt = 'Hiển thị';
					$submit = 'unpublish';
				}else{
					$img = 'publish_x.png';
					$alt = 'Khóa';
					$submit = 'publish';
				}
				if ($rows[$i]->vip == 1){
					$imgVip = 'vip.png';
					$altVip = 'Nhóm VIP';
					$widthVip = 39;
					$heightVip = 19;
				}else{
					$imgVip = 'publish_r.png';
					$altVip = 'Không thuộc nhóm VIP';
					$widthVip = 12;
					$heightVip = 12;
				}
				if ($rows[$i]->hits == 1){
					$imgHot = 'hot.png';
					$altHot = 'Nhóm Hot';
					$widthHot = 50;
					$heightHot = 11;
				}else{
					$imgHot = 'publish_r.png';
					$altHot = 'Không thuộc nhóm Hot';
					$widthHot = 12;
					$heightHot = 12;
				}	
				?>
				<tr class="<?php echo $str_class;?>">
					<td><input type="checkbox" onclick="isChecked(this.checked);" value="<?php echo $rows[$i]->id;?>" name="cid[]" id="cb<?php echo $i;?>" /></td>
					<td>
						<a href="<?php echo $link;?>" title="<?php echo $rows[$i]->title;?>" target="_blank">
						<?php if($rows[$i]->thumbnailImage!=''){?>
						<img src="<?php echo $imageurl;?>/thumbnail/<?php echo $rows[$i]->thumbnailImage;?>" width="20" border="0" />
						<?php }else{?>
						<img src="<?php echo $mosConfig_live_site;?>/templates/html_ngayhomnay/images/nopic.gif" width="20" border="0" />
						<?php }?>
						</a>
					</td>
					<td><a href="<?php echo $linkEdit;?>"title="Cập nhật sản phẩm <?php echo $rows[$i]->title;?>"><?php echo $rows[$i]->title;?></a></td>
					<td><a href="<?php echo $linkCat;?>" class="category"><?php echo $rows[$i]->titlecat;?></a></td>
					<td align="center"><?php echo unFormatDate($rows[$i]->created, "d/m/Y");?></td>
					<td align="center"><img src="<?php echo $mosConfig_live_site;?>/images/<?php echo $imgVip;?>" width="<?php echo $widthVip;?>" height="<?php echo $heightVip;?>" border="0" alt="<?php echo $altVip; ?>" /></td>
					<td align="center"><img src="<?php echo $mosConfig_live_site;?>/images/<?php echo $imgHot;?>" width="<?php echo $widthHot;?>" height="<?php echo $heightHot;?>" border="0" alt="<?php echo $altHot; ?>" /></td>
					<td align="center">
						<a onclick="return listItemTask('cb<?php echo $i;?>','<?php echo $submit;?>')" href="javascript: void(0);">
						<img src="<?php echo $mosConfig_live_site;?>/images/<?php echo $img;?>" width="12" height="12" border="0" alt="<?php echo $alt; ?>" />
						</a>
					</td>
					<td align="center">Xem thống kê</td>
				</tr>
				<?php }?>
			<?php }else{?>
				<tr>
					<td align="center" colspan="9"><b style="color:red;"><?php echo _CONTENT_NOT_FOUND;?></b></td>
				</tr>
			<?php }?>
			</tbody>
			<tfoot></tfoot>
		</table>
		<input type="hidden" name="option" value="com_user" />
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="boxchecked" value="0" />
		<input type="hidden" name="hidemainmenu" value="0" />
		<input type="hidden" name="<?php echo josSpoofValue(); ?>" value="1" />
		</form>
		<?php
		}
	}
	
	/**
	 * Edit Product
	*/
	function editProduct( &$row, &$lsSection, &$lsCategories, &$listHangsx ){
		global $mosConfig_live_site, $mosConfig_absolute_path;
		global $database;
		$title			= mosGetParam($_REQUEST, 'title', '');
		$sectionid		= intval(mosGetParam($_REQUEST, 'sectionid', 0));
		$catid			= intval(mosGetParam($_REQUEST, 'catid', 0));
		if ($hiddenmain == 1){
			$styleDisplay = ' style="display:none;"';
		}else{
			$styleDisplay = '';
		}
		
		require_once( $mosConfig_absolute_path .'/includes/HTML_toolbar.php' );
		
		mosMakeHtmlSafe( $row );
		mosCommonHTML::loadOverlib();
		mosCommonHTML::loadCalendar();
		
		$imageurl 	= $mosConfig_live_site."/uploads/content";
		?>
		<script language="JavaScript" src="<?php echo $mosConfig_live_site; ?>/includes/js/joomla.javascript.js" type="text/javascript"></script>
		<link rel="stylesheet" href="<?php echo $mosConfig_live_site; ?>/plugin/jwysiwyg/jwysiwyg/jquery.wysiwyg.css" type="text/css" />
		<script type="text/javascript" src="<?php echo $mosConfig_live_site; ?>/plugin/jwysiwyg/jwysiwyg/jquery.wysiwyg.js"></script>
		<script type="text/javascript" src="<?php echo $mosConfig_live_site;?>/includes/jquery_upload_crop/js/jquery-pack.js"></script>
		<script type="text/javascript" src="<?php echo $mosConfig_live_site;?>/includes/jquery_upload_crop/js/jquery.imgareaselect-0.3.min.js"></script>
		<script language="javascript" type="text/javascript">
		function delete_extra_options (selobj, size)
		{
			while (selobj . options . length > size)
				selobj . options [selobj . options . length - 1] = null;
		}
		
		function update_item_list ()
		{
			var cat_selobj = document . adminForm . sectionid;
			var item_selobj = document . adminForm . catid;
			var choice = cat_selobj . options [cat_selobj . selectedIndex] . value;
			<?php
			for ($i=0; $i<count($lsSection); $i++){
				?>
				if (choice == <?php echo $lsSection[$i]->id;?>)
				{
					<?php
					$sql = "SELECT COUNT(*) FROM #__categories WHERE published=1 AND section=".$lsSection[$i]->id;
					$database->setQuery($sql);
					$total = $database->loadResult();
					$sql = "SELECT id,title FROM #__categories WHERE published=1 AND section=".$lsSection[$i]->id." ORDER BY ordering ASC, id DESC";
					$database->setQuery($sql);
					$lsCate = $database->loadObjectList();
					for ($j=0; $j<count($lsCate); $j++){
					?>
					item_selobj . options [<?php echo $j;?>] = new Option ("<?php echo $lsCate[$j]->title;?>","<?php echo $lsCate[$j]->id;?>");
					<?php
					}
					?>
					delete_extra_options (item_selobj, <?php echo $total;?>);
				}
				<?php
			}
			?>
		}
		function submitbutton(pressbutton) {
			var form = document.adminForm;
			if (pressbutton == 'cancel') {
				submitform( pressbutton );
				return;
			}
			// do field validation
			if (form.title.value == ""){
				alert( "Vui lòng nhập tên sản phẩm !" );
			} else if (form.sectionid.value == "-1"){
				alert( "Vui lòng chọn nhóm sản phẩm." );
			} else if (form.catid.value == "-1"){
				alert( "Vui lòng lựa chọn tên nhóm sản phẩm." );
 			} else if (form.catid.value == ""){
 				alert( "Vui lòng lựa chọn tên nhóm sản phẩm." );
			}
//			else if (form.catphone_id.value == ""){
// 				alert( "Vui lòng chọn hãng sản xuất." );
//			}
			 else {
				submitform( pressbutton );
			}
		}
		</script>
		<form action="" method="post" name="adminForm" enctype="multipart/form-data"<?php echo $styleDisplay;?>>
		<div class="user_heading">
			<div id="title_form">Cập nhật sản phẩm</div>
			<div id="toolbar">
			<?php
			mosToolBar::startTable();
			mosToolBar::saveIcon();
			mosToolBar::cancelIcon();
			mosToolBar::endtable();
			?>
			</div>
		</div>
		<table width="100%" class="adminlist">
		<tr>
			<td width="100%">
				<table cellspacing="0" cellpadding="0" border="0" width="100%">
				<tr>
					<th colspan="4">
					THÔNG TIN CHI TIẾT
					</th>
				</tr>
				<tr>
					<td>
					Tên sản phẩm:
					</td>
					<td>
					<?php
					if ($row->id > 0 ){
						$value_title = $row->title; 
					}else{
						$value_title = $title;
					}
					?>
					<input class="inputbox" type="text" name="title" size="30" maxlength="100" value="<?php echo $value_title; ?>" />
					</td>
					<td>
					Nhóm sản phẩm:
					</td>
					<td>
						<select onChange="update_item_list();" size="1" name="sectionid" id="sectionid" title="Chọn" class="inputbox">
							<option value="-1">Lựa chọn nhóm sản phẩm</option>
							<?php
							for ($i=0; $i<count($lsSection); $i++){
								if ($row->id > 0 ){
									if ($lsSection[$i]->id == $row->sectionid) $selected = ' selected="selected"';
									else $selected = '';
								}else{
									if ($lsSection[$i]->id == $sectionid) $selected = ' selected="selected"';
									else $selected = '';
								}
								echo "<option value='".$lsSection[$i]->id."'".$selected.">".$lsSection[$i]->title."</option>";
							}
							?> 
						</select>
					</td>
				</tr>
				<tr>
					<td>
					Seo tên:
					</td>
					<td>
					<input name="title_alias" type="text" class="inputbox" id="title_alias" value="<?php echo $row->title_alias; ?>" size="30" maxlength="100" disabled="disabled" />
					</td>
					<td>
					Loại sản phẩm:
					</td>
					<td>
						<select onchange="" size="1" name="catid" id="catid" title="Chọn" class="inputbox">
							<option value="-1">Lựa chọn loại sản phẩm</option>
							<?php
							for ($i=0; $i<count($lsCategories); $i++){
								if ($row->id > 0 ){
									if ($lsCategories[$i]->id == $row->catid) $selected = ' selected="selected"';
									else $selected = '';
								}else{
									if ($lsCategories[$i]->id == $catid) $selected = ' selected="selected"';
									else $selected = '';
								}
								echo "<option value='".$lsCategories[$i]->id."'".$selected.">".$lsCategories[$i]->title."</option>";
							}
							?>
						</select>
					</td>
				</tr>
				<?php if ($row->id==0 || ($row->largeImage=='' || !$row->largeImage)){?>
				<tr>
					<td>
					Chọn ảnh:
					</td>
					<td>
					 <input type="file" name="image" size="30" />
					</td>
					<td>
					Upload ảnh:
					</td>
					<td>
					<input type="button" name="upload" onclick="javascript:submitbutton('upload');" value="Upload" />
					</td>
				</tr>
				<?php }?>
				<tr>
					<td colspan="4">
					<?php
					$upload_dir = $mosConfig_live_site."/uploads/temp";
					$upload_path = $upload_dir."/";
					$large_image_name = "temp_pic.jpg";
					$max_file = "1148576";
					$max_width = "500";
					$thumb_width = "100";
					$thumb_height = "100";
							
					//Image Locations
					$large_image_location = $upload_path.$large_image_name;
							
					//Create the upload directory with the right permissions if it doesn't exist
					if(!is_dir($upload_dir)){
						mkdir($upload_dir, 0777);
								//chmod($upload_dir, 0777);
					}
							
					//Check to see if any images with the same names already exist
					if (file_exists($large_image_location)){
						$large_photo_exists = "<img src=\"".$upload_path.$large_image_name."\" alt=\"Large Image\" width=\"450\" border=\"0\" />";
					} else {
						$large_photo_exists = "";
					}
							
					//Only display the javacript if an image has been uploaded
					//if(strlen($large_photo_exists)>0){
					//$current_large_image_width = getWidth($large_image_location);
					//$current_large_image_height = getHeight($large_image_location);
					$current_large_image_width = 450;
					$current_large_image_height = 320;
					?>
					<script type="text/javascript">
					function preview(img, selection) { 
						var scaleX = <?php echo $thumb_width;?> / selection.width; 
						var scaleY = <?php echo $thumb_height;?> / selection.height; 
							
						$('#thumbnail + div > img').css({ 
							width: Math.round(scaleX * <?php echo $current_large_image_width;?>) + 'px', 
							height: Math.round(scaleY * <?php echo $current_large_image_height;?>) + 'px',
							marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px', 
							marginTop: '-' + Math.round(scaleY * selection.y1) + 'px' 
						});
						$('#x1').val(selection.x1);
						$('#y1').val(selection.y1);
						$('#x2').val(selection.x2);
						$('#y2').val(selection.y2);
						$('#w').val(selection.width);
						$('#h').val(selection.height);
					} 
					<?php if ($row->id==0 || ($row->largeImage=='' || !$row->largeImage)){?>
					$(document).ready(function () {
						$('#save_thumb').click(function() {
							var x1 = $('#x1').val();
							var y1 = $('#y1').val();
							var x2 = $('#x2').val();
							var y2 = $('#y2').val();
							var w = $('#w').val();
							var h = $('#h').val();
							if(x1=="" || y1=="" || x2=="" || y2=="" || w=="" || h==""){
								alert("Vui lòng lựa chọn ảnh đại điện cho sản phẩm của bạn bằng cách bấm vào ảnh và chọn vùng ảnh bạn muốn !");
								return false;
							}else{
								return true;
							}
						});
					}); 
					<?php }?>
						
					$(window).load(function () { 
						$('#thumbnail').imgAreaSelect({ aspectRatio: '1:1', onSelectChange: preview }); 
					});
					</script>
					<?php
					if ($row->id==0 || ($row->largeImage=='' || !$row->largeImage)){
					?>
					<img src="<?php echo $upload_path.$large_image_name;?>" style="float: left; margin-right: 10px;" id="thumbnail" width="650" border="0" alt="Tạo ảnh đại diện" />
					<div style="float:left; position:relative; overflow:hidden; width:<?php echo $thumb_width;?>px; height:<?php echo $thumb_height;?>px;">
						<img src="<?php echo $upload_path.$large_image_name;?>" style="position: relative;" alt="Ảnh đại diện" />
					</div>
					<?php 
					}else{
						if ($row->largeImage=='' || !$row->largeImage){
						?>
							<img id="pic"  src="<?php echo $mosConfig_live_site;?>/uploads/no_pic.gif" width="160" border="0" />
							<?php
						}
						else{
							?>
							<img id="pic" src="<?php echo $mosConfig_live_site;?>/uploads/content/large/<?php echo $row->largeImage;?>" width="160" border="0" />
							<?php
						}
						if ($row->mediumImage=='' || !$row->mediumImage){
						?>
							<img id="pic"  src="<?php echo $mosConfig_live_site;?>/uploads/no_pic.gif" width="120" border="0" />
							<?php
						}
						else{
							?>
							<img id="pic" src="<?php echo $mosConfig_live_site;?>/uploads/content/medium/<?php echo $row->mediumImage;?>" width="120" border="0" />
							<?php
						}
						if ($row->thumbnailImage=='' || !$row->thumbnailImage){
						?>
							<img id="pic"  src="<?php echo $mosConfig_live_site;?>/uploads/no_pic.gif" width="80" border="0" />
							<?php
						}
						else{
							?>
							<img id="pic" src="<?php echo $mosConfig_live_site;?>/uploads/content/thumbnail/<?php echo $row->thumbnailImage;?>" width="80" border="0" />
							<?php
						}
						if ($row->id!=0 && $row->largeImage!=''){
							?>
							<input type="button" name="delete" onclick="javascript:submitbutton('delImage');" value="Xóa ảnh" />
							<?php
						}
					}
					?>
					</td>
				</tr>
				<tr>
					<td>
					Mã sản phẩm:
					</td>
					<td>
					<input class="inputbox" type="text" name="code" size="30" maxlength="100" value="<?php echo $row->code; ?>" />
					</td>
					<td>
					Hãng sản xuất:
					</td>
					<td>
					<select class="inputbox" name="catphone_id">
						<option value="">Lựa chọn hãng sản xuất</option>
						<?php
						for ($i=0; $i<count($listHangsx); $i++){
							if ($listHangsx[$i]->id == $row->catphone_id) $selected = ' selected="selected"';
							else $selected = '';
							echo "<option value='".$listHangsx[$i]->id."'".$selected.">".$listHangsx[$i]->name."</option>";
						}
						?>
					</select>
					</td>
				</tr>
				<tr>
					<td>
					Giá bán:
					</td>
					<td>
					<input class="inputbox" type="text" name="price" size="30" maxlength="30" value="<?php echo $row->price; ?>" />
					</td>
					<td>
					Giá đã giảm:
					</td>
					<td>
					<input class="inputbox" type="text" name="price_giam" size="30" maxlength="30" value="<?php echo $row->price_giam; ?>" />
					</td>
				</tr>
				<tr>
					<td>
					Mức giảm:
					</td>
					<td>
					<input class="inputbox" type="text" name="muc_giam" size="30" maxlength="30" value="<?php echo $row->muc_giam; ?>" disabled="disabled" />
					</td>
					<td>
					(%) giảm:
					</td>
					<td>
					<input class="inputbox" type="text" name="giam_gia" size="30" maxlength="30" value="<?php echo $row->giam_gia;?>" disabled="disabled" /> <label>(%)</label>
					</td>
				</tr>
				<tr>
					<td>
					Bảo hành:
					</td>
					<td>
					<input class="inputbox" type="text" name="bao_hanh" size="30" value="<?php echo $row->bao_hanh; ?>" />
					</td>
					<td>
					Đơn vị tính:
					</td>
					<td>
					<input class="inputbox" type="text" name="don_vi" size="30" value="<?php echo $row->don_vi; ?>" />
					</td>
				</tr>						
				</table>
			</td>
		</tr>
		<tr>
			<td width="100%">
			Mô tả ngắn:
			<br />
			<textarea rows="5" cols="60" name="introtext"><?php echo $row->introtext;?></textarea>
			</td>
		</tr>
		<tr>
			<td width="100%">
			Mô tả chi tiết:
			<br />
			<textarea id="wysiwyg" rows="30" cols="90" name="fulltext"><?php echo $row->fulltext;?></textarea>
			</td>
		</tr>
		</table>
		<table class="adminlist">
		<tr>
			<th colspan="2">
			THÔNG TIN HIỂN THỊ
			</th>
		</tr>
		<tr>
			<td valign="top" align="right">
			Hiển thị sản phẩm:
			</td>
			<td>
			<input type="checkbox" name="state" value="1" <?php if($row->state==1) echo "checked='checked'"; ?> /> Hiển thị					
			</td>
		</tr>
		<?php
		$time = time();					
		if ($rowid==0){
			$ngay_nhap_sp = date('Y-m-d',$time);
		}else{
			$ngay_nhap_sp = $row->created;
		}
		?>				
		<tr>
			<td valign="top" align="right">
			Ngày đăng
			</td>
			<td>
			<input class="inputbox" type="text" name="created" id="created" size="25" maxlength="19" value="<?php echo $ngay_nhap_sp; ?>" />
			<input name="reset" type="reset" class="button" onclick="return showCalendar('created', 'y-mm-dd');" value="..." />
			</td>
		</tr>
		</table>
		
		<input type="hidden" name="id" value="<?php echo $row->id; ?>" />
		<input type="hidden" name="option" value="com_user" />
		<input type="hidden" name="task" value="" />
		
		<input type="hidden" name="x1" value="" id="x1" />
		<input type="hidden" name="y1" value="" id="y1" />
		<input type="hidden" name="x2" value="" id="x2" />
		<input type="hidden" name="y2" value="" id="y2" />
		<input type="hidden" name="w" value="" id="w" />
		<input type="hidden" name="h" value="" id="h" />
		</form>
		<script language="javascript" type="text/javascript">
		$(document).ready(function () {
			$('.inputbox').css('width','250px');
			$(function(){
				$('#wysiwyg').wysiwyg();
			});
		}); 
		</script>
		<?php
	}
}
?>